package com.qf.controller;

import com.qf.bean.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * projectName: 2103--RBAC
 *
 * @author: MaTianWei
 * time: 2021/7/8 20:25
 * description:用户授权Controller
 */
@Controller
@RequestMapping("user")
@SessionAttributes(names={"ret"})
public class UserController {

    @Autowired
    private UserService userService;
    @GetMapping("index")
    public String indexHtml(){
        return "index";
    }
    @GetMapping("logout")
    public String logout(SessionStatus sessionStatus){
        //清空数据
        sessionStatus.setComplete();
        return "login";
    }

    @GetMapping("html")
    public String loginHtml(){
        System.out.println("跳转登录界面");
        return "login";
    }
    @PostMapping("login")
    public ModelAndView login(User user){
        Map ret = userService.login(user);
        System.out.println("ret="+ret);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("ret",ret);
        modelAndView.setViewName("index");
        return modelAndView;
    }
    //未认证
    @GetMapping("noauthentication")
    public String noauthentication(){
        return "noauthentication";
    }
    //未授权
    @GetMapping("noauthorization")
    public String noauthorization(){
        return "noauthorization";
    }
}
